package testJdk.io.filewriter;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @ClassName : com.io.filewriter.TestCopy1
 * @Description : 类描述
 * Created by cyd on 2020-12-09 23:12:11
 */
public class TestCopy2 {
    public static void main(String[] args) throws IOException {
        //1.创建输入流和输出流

        try (FileReader fr = new FileReader("D:\\readme.txt");
             FileWriter fw = new FileWriter("D:\\readme2.txt")) {
            //2.使用流，复制文件
            //定义一个中转站 cbuf
            char[] cbuf = new char[1024];
            int len = fr.read(cbuf);
            while (-1 != len) {
                fw.write(cbuf, 0, len);
                System.out.println(cbuf);
                System.out.println(new String(cbuf, 0, len));
                len = fr.read(cbuf);
            }
        }

        //3.关闭流
        //fr.close();
        //fw.close();
    }
}
